
//
//  DynamicMoreView.m
//  MJApp
//
//  Created by wangliang on 15/5/30.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "DynamicMoreView.h"

@interface DynamicMoreView ()

@property(nonatomic,strong)UIButton *deleteBtn;

@end

@implementation DynamicMoreView

- (instancetype)init {
    
    if (self = [super init]) {
        
        [self UI];
    }
    return self;
}

- (void)setState:(DynamicMoreViewState)state {
    
    _state = state;
    if (state == DynamicMoreViewStateOther) {
        
        self.deleteBtn.hidden = YES;
    }else {
        
        self.deleteBtn.hidden = NO;
    }
}

- (void)UI {
    
    CGRect frame = [UIApplication sharedApplication].keyWindow.bounds;
    self.frame = CGRectMake(0, 0, frame.size.width, 170);
    
    CGFloat high = 56;
    UIButton *deleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.frame), high)];
    deleteBtn.backgroundColor = [UIColor whiteColor];
    [deleteBtn setTitle:@"删除" forState:UIControlStateNormal];
    [deleteBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self addSubview:deleteBtn];
    self.deleteBtn = deleteBtn;
    
    UIButton *shareBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(deleteBtn.frame) + 0.5, CGRectGetWidth(self.frame), high)];
    shareBtn.backgroundColor = [UIColor whiteColor];
    [shareBtn setTitle:@"分享" forState:UIControlStateNormal];
    [shareBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [self addSubview:shareBtn];
    
    UIButton *cancelBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(shareBtn.frame) + 2, CGRectGetWidth(self.frame), high)];
    cancelBtn.backgroundColor = [UIColor whiteColor];
    [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
    [cancelBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [self addSubview:cancelBtn];
    
    deleteBtn.tag = 1;
    shareBtn.tag = 2;
    cancelBtn.tag = 3;
    
    [deleteBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [shareBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [cancelBtn addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)buttonAction:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(homeCell:withInfo:)]) {
        NSDictionary *dic = @{@"index":@(sender.tag)};
        [self.delegate homeCell:self withInfo:dic];
    }
}

@end
